home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Packer / xad / Developer / Sources / tools / xadUnFile.c < prev   
C/C++ Source or Header  |  1999-11-06  |  11KB  |  370 lines

  1. #define NAME         "xadUnFile"
  2. #define DISTRIBUTION "(Freeware) "
  3. #define REVISION     "1"
  4.  
  5. /* Programmheader
  6.  
  7.     Name:        xadUnFile
  8.     Author:        SDI
  9.     Distribution:    Freeware
  10.     Description:    dearchives file archives
  11.     Compileropts:    -
  12.     Linkeropts:    -gsi -l amiga
  13.  
  14.  1.0   13.09.98 : first version
  15.  1.1   18.11.98 : added FILE parameter and directory creation
  16. */
  17.  
  18. #include <proto/xadmaster.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <exec/memory.h>
  22. #include <dos/dosasl.h>
  23. #include <utility/hooks.h>
  24. #include "SDI_defines.h"
  25. #include "SDI_compiler.h"
  26. #define SDI_TO_ANSI
  27. #include "SDI_ASM_STD_protos.h"
  28.  
  29. #ifdef __SASC
  30.   #define xadmasterbase     xadMasterBase 
  31.   #define ASSIGN_XAD
  32. #else
  33.   struct xadMasterBase * xadMasterBase = 0;
  34.   #define ASSIGN_XAD     xadMasterBase = xadmasterbase;
  35. #endif
  36. struct DosLibrary *     DOSBase = 0;
  37. struct ExecBase *     SysBase  = 0;
  38.  
  39. #define PARAM    "FROM/A,DESTDIR,PASSWORD/K,FILE/M,NE=NOEXTERN/S,"     \
  40.         "INFO=LIST/S,OW=OVERWRITE/S,NOTREE/S,ASKMAKEDIR/S,"    \
  41.         "NOCOMMENT/S,NOPROT/S,NODATE/S"
  42.  
  43. #define OPTIONS \
  44.   "FROM       The input archive file (no patterns allowed)\n"        \
  45.   "DESTDIR    The destination directory, not needed with INFO\n"    \
  46.   "PASSWORD   A password for encrypted archives\n"            \
  47.   "FILE       Multiple filenames (with patterns) to be extracted\n"    \
  48.   "NOEXTERN   Turns off usage of external clients\n"            \
  49.   "INFO       Shows archive information without extracting\n"        \
  50.   "OVERWRITE  Files are overwritten without asking\n"            \
  51.   "NOTREE     Files are extracted without subdirectories\n"        \
  52.   "ASKMAKEDIR You get asked before a directory is created\n"        \
  53.   "NOCOMMENT  No filenote comments are extracted\n"            \
  54.   "NOPROT     Protection information gets not extracted\n"        \
  55.   "NODATE     Creation date information gets not extracted\n"        \
  56.  
  57. struct xHookArgs {
  58.   STRPTR name;
  59.   ULONG flags;
  60. };
  61.  
  62. struct Args {
  63.   STRPTR   from;
  64.   STRPTR   destdir;
  65.   STRPTR   password;
  66.   STRPTR * file;
  67.   ULONG    noextern;
  68.   ULONG    info;
  69.   ULONG    overwrite;
  70.   ULONG    notree;
  71.   ULONG    askmakedir;
  72.   ULONG    nocomment;
  73.   ULONG    noprot;
  74.   ULONG    nodate;
  75. };
  76.  
  77. ASM(ULONG) progrhook(REG(a0, struct Hook *),
  78.   REG(a1, struct xadProgressInfo *));
  79. LONG CheckName(STRPTR *pat, STRPTR name);
  80.  
  81. ULONG start(void)
  82. {
  83.   ULONG ret = RETURN_FAIL;
  84.   struct DosLibrary *dosbase;
  85.  
  86.   SysBase = (*((struct ExecBase **) 4));
  87.   { /* test for WB and reply startup-message */
  88.     struct Process *task;
  89.     if(!(task = (struct Process *) FindTask(0))->pr_CLI)
  90.     {
  91.       WaitPort(&task->pr_MsgPort);
  92.       Forbid();
  93.       ReplyMsg(GetMsg(&task->pr_MsgPort));
  94.       return RETURN_FAIL;
  95.     }
  96.   }
  97.  
  98.   if((dosbase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
  99.   {
  100.     LONG err = 0;
  101.     struct xadMasterBase *xadmasterbase;
  102.  
  103.     DOSBase = dosbase;
  104.     if((xadmasterbase = (struct xadMasterBase *)
  105.     OpenLibrary("xadmaster.library", 1)))
  106.     {
  107.       struct Args args;
  108.       struct RDArgs *rda;
  109.       
  110.       memset(&args, 0, sizeof(struct Args));
  111.       ASSIGN_XAD
  112.  
  113.       if((rda = (struct RDArgs *) AllocDosObject(DOS_RDARGS, 0)))
  114.       {
  115.         rda->RDA_ExtHelp = OPTIONS;
  116.  
  117.         if(ReadArgs(PARAM, (LONG *) &args, rda))
  118.         {
  119.       if(args.destdir || args.info)
  120.       {
  121.         struct xadArchiveInfo *ai;
  122.     
  123.         if((ai = (struct xadArchiveInfo *)
  124.         xadAllocObjectA(XADOBJ_ARCHIVEINFO, 0)))
  125.         {
  126.           if(!(err = xadGetInfo(ai, XAD_INFILENAME, args.from,
  127.           XAD_NOEXTERN, args.noextern, args.password ? XAD_PASSWORD :
  128.           TAG_IGNORE, args.password, TAG_DONE)))
  129.           {
  130.             if(args.info)
  131.             {
  132.               struct xadFileInfo *xfi;
  133.               Printf("ArchiverName:   %s\n"
  134.           "Size     CrndSize Date       Time     Name\n",
  135.           ai->xai_Client->xc_ArchiverName);
  136.  
  137.               xfi = ai->xai_FileInfo;
  138.               while(xfi && !CTRL_C)
  139.               {
  140.             if(xfi->xfi_Flags & XADFIF_DIRECTORY)
  141.             {
  142.               if(!args.notree)
  143.                     Printf("   <dir>    <dir> %02ld.%02ld.%04ld %02ld:%02ld:%02ld %s\n",
  144.                     xfi->xfi_Date.xd_Day, xfi->xfi_Date.xd_Month,
  145.                     xfi->xfi_Date.xd_Year, xfi->xfi_Date.xd_Hour,
  146.                     xfi->xfi_Date.xd_Minute, xfi->xfi_Date.xd_Second,
  147.                     xfi->xfi_FileName);
  148.                 }
  149.             else
  150.                   Printf("%8ld %8ld %02ld.%02ld.%04ld %02ld:%02ld:%02ld %s\n",
  151.                   xfi->xfi_Size, xfi->xfi_CrunchSize,
  152.                   xfi->xfi_Date.xd_Day, xfi->xfi_Date.xd_Month,
  153.                   xfi->xfi_Date.xd_Year, xfi->xfi_Date.xd_Hour,
  154.                   xfi->xfi_Date.xd_Minute, xfi->xfi_Date.xd_Second,
  155.                   args.notree ? FilePart(xfi->xfi_FileName) :
  156.                   xfi->xfi_FileName);
  157. #ifdef DEBUG
  158.             if(xfi->xfi_Flags)
  159.             {
  160.                   Printf("Flags:          ");
  161.                   if(xfi->xfi_Flags & XADFIF_CRYPTED)
  162.                     Printf("XADFIF_CRYPTED ");
  163.                   if(xfi->xfi_Flags & XADFIF_DIRECTORY)
  164.                     Printf("XADFIF_DIRECTORY ");
  165.                   if(xfi->xfi_Flags & XADFIF_LINK)
  166.                     Printf("XADFIF_LINK ");
  167.                   if(xfi->xfi_Flags & XADFIF_INFOTEXT)
  168.                     Printf("XADFIF_INFOTEXT ");
  169.                   if(xfi->xfi_Flags & XADFIF_GROUPED)
  170.                     Printf("XADFIF_GROUPED ");
  171.                   if(xfi->xfi_Flags & XADFIF_ENDOFGROUP)
  172.                     Printf("XADFIF_ENDOFGROUP ");
  173.                   Printf("\n");
  174.                 }
  175. #endif
  176.                 if(xfi->xfi_Flags & XADFIF_CRYPTED)
  177.                   Printf("The entry is encrypted\n");
  178.                 xfi = xfi->xfi_Next;
  179.               }
  180.               ret = 0;
  181.             }
  182.             else
  183.             {
  184.           struct Hook prhook;
  185.           struct xadFileInfo *fi;
  186.           UBYTE filename[256];
  187.           struct xHookArgs xh;
  188.         
  189.           xh.name = filename;
  190.           xh.flags = 0;
  191.  
  192.               memset(&prhook, 0, sizeof(struct Hook));
  193.               prhook.h_Entry = (ULONG (*)()) progrhook;
  194.               prhook.h_Data = &xh;
  195.           fi = ai->xai_FileInfo;
  196.           while(!err && fi)
  197.           {
  198.             if(!args.file || CheckName(args.file, args.notree ?
  199.             FilePart(fi->xfi_FileName) : fi->xfi_FileName))
  200.             {
  201.               CopyMem(args.destdir, filename, strlen(args.destdir)+1);
  202.               AddPart(filename, args.notree ? FilePart(fi->xfi_FileName) :
  203.               fi->xfi_FileName, 256);
  204.               if(fi->xfi_Flags == XADFIF_DIRECTORY)
  205.               {
  206.                 if(!args.notree)
  207.                 {
  208.                   BPTR a;
  209.                   LONG err = 0, i = 0;
  210.                   UBYTE r;
  211.                   while(filename[i] && !err)
  212.                   {
  213.                       for(;filename[i] && filename[i] != '/'; ++i)
  214.                       ;
  215.                       r = filename[i];
  216.                       filename[i] = 0;
  217.                 if((a = Lock(filename, SHARED_LOCK)))
  218.                         UnLock(a);
  219.                     else if((a = CreateDir(filename)))
  220.                           UnLock(a);
  221.                       else
  222.                           err = 1;
  223.                         filename[i++] = r;
  224.                   }
  225.                   if(err)
  226.                     Printf("failed to create directory '%s'\n",
  227.                     fi->xfi_FileName);
  228.                   else
  229.                     Printf("Created directory   : %s\n", filename);
  230.                 }
  231.               } 
  232.               else if(fi->xfi_Flags & XADFIF_LINK)
  233.               {
  234.                 Printf("Skipped Link\n");
  235.               }
  236.               else
  237.               {
  238.                 struct DateStamp d;
  239.  
  240.                 if((err = xadFileUnArc(ai, XAD_OUTFILENAME, filename,
  241.                     XAD_ENTRYNUMBER, fi->xfi_EntryNumber, XAD_MAKEDIRECTORY,
  242.                     !args.askmakedir, XAD_OVERWRITE, args.overwrite,
  243.                     XAD_PROGRESSHOOK, &prhook, TAG_DONE)) == XADERR_SKIP)
  244.                       err = 0;
  245.                     else if(!err)
  246.                     {
  247.                       if(!args.nodate && !xadConvertDates(XAD_DATEXADDATE,
  248.                       &fi->xfi_Date, XAD_GETDATEDATESTAMP, &d, TAG_DONE))
  249.                         SetFileDate(filename, &d);
  250.                       if(!args.noprot)
  251.                         SetProtection(filename, fi->xfi_Protection);
  252.                       if(fi->xfi_Comment && !args.nocomment)
  253.                         SetComment(filename, fi->xfi_Comment);
  254.                       /* SetOwner ??? */
  255.                     }
  256.                   }
  257.                 }
  258.                 fi = fi->xfi_Next;
  259.               }
  260.               if(!err)
  261.                 ret = 0;
  262.             }
  263.             xadFreeInfo(ai);
  264.           } /* xadGetInfo */
  265.  
  266.           xadFreeObjectA(ai, 0);
  267.             } /* xadAllocObject